/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * inicio.java
 *
 * Created on 14/09/2012, 12:13:14 PM
 */
package interfaz;

import interfaz.Ciudad;
import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JFrame;
import simulacion.DMapa;

/**
 *
 * @author Isis
 */
public class mapa extends javax.swing.JPanel {

    /**
     * Creates new form inicio
     */
    public mapa() {
        initComponents();
        inicializarLayout();
    }

    public void inicializarLayout() {

        this.setLayout(null);
        this.panelRutas.setBounds(interfaz.variables.panelRutasX, interfaz.variables.panelRutasY,
                interfaz.variables.anchoRutas, interfaz.variables.altoRutas);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelRutas = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        contenedor = new javax.swing.JPanel();

        setBackground(new java.awt.Color(200, 106, 38));
        setPreferredSize(new java.awt.Dimension(916, 462));

        panelRutas.setBackground(new java.awt.Color(204, 204, 204));

        jPanel2.setBackground(new java.awt.Color(0, 0, 0));

        jButton1.setText("Crear Mapa");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(701, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton1)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        contenedor.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout contenedorLayout = new javax.swing.GroupLayout(contenedor);
        contenedor.setLayout(contenedorLayout);
        contenedorLayout.setHorizontalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 820, Short.MAX_VALUE)
        );
        contenedorLayout.setVerticalGroup(
            contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 339, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout panelRutasLayout = new javax.swing.GroupLayout(panelRutas);
        panelRutas.setLayout(panelRutasLayout);
        panelRutasLayout.setHorizontalGroup(
            panelRutasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRutasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(contenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        panelRutasLayout.setVerticalGroup(
            panelRutasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRutasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(contenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(panelRutas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelRutas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Ciudad C = new Ciudad();
        C.setBounds(0, 0, interfaz.variables.anchoRutas, interfaz.variables.altoRutas);
        this.contenedor.setLayout(null);

        parsearArchivo(C);

        this.contenedor.add(C);
        this.contenedor.setVisible(false);
        this.contenedor.setVisible(true);
        ArrayList<String> rutas = new ArrayList<String>();
		rutas.add("CCAACC");
		rutas.add("AACC");
        
         getSimulacion(rutas, 5, 5, DMapa.HORIZONTAL);
        /* Si es avenida es Horizontal de lo contrario vertical
         * getSimulacion(ArrayList<String>, int, int, DMapa.HORIZONTAL);
         * o
         * getSimulacion(ArrayList<String>, int, int, DMapa.VERTICAL);
         */
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    public void parsearArchivo(Ciudad C) {
        // al parsear el tamaño
        C.dibujarCiudadCentro(5, 5);

        C.dibujarCiudad(10, 10);

        C.dibujarSemaforo(2, 2, "C");
        C.dibujarSemaforo(2, 2, "A");

        C.dibujarAgujero(3, 3, "A");
        C.dibujarAgujero(3, 8, "C");

        C.dibujarAreaComercial(4, 1, "A");
        C.dibujarAreaComercial(1, 7, "C");


        C.dibujarEscuela(2, 3, "A");
        C.dibujarEscuela(2, 5, "C");

        C.dibujarObjeto(4, 6, "A");
        C.dibujarObjeto(6, 2, "C");

        C.dibujarReductor(3, 8, "A");
        C.dibujarReductor(6, 1, "C");


    }
    
    public void getSimulacion( ArrayList<String> rutas, int punto1, int punto2, byte orientacion ){
        JFrame jfSimulacion = new JFrame("Simulacion");
        jfSimulacion.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        jfSimulacion.setSize(500,500);
        jfSimulacion.setExtendedState(JFrame.MAXIMIZED_BOTH);
        jfSimulacion.setLocationRelativeTo(null);
        jfSimulacion.setLayout(new BorderLayout());
        
        DMapa dm = new DMapa( punto1,punto2, orientacion);
        dm.setSolucion(rutas);
        Thread hilo = new Thread( dm );
        jfSimulacion.add( dm, BorderLayout.CENTER );
        jfSimulacion.setVisible(true);
        hilo.start();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel contenedor;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel panelRutas;
    // End of variables declaration//GEN-END:variables
}
